# # 1 基础格式认识
# num = [1, 2, 3, 4, 5]
# prog = int(input('please input the value of prog:'))
# for number in num:
#     prog = prog * number
# print('the prog is: ', prog)
#
# # 2 input输入
# price = input('pls input the stock price of apple: ')
# type(price)
# price = int(input('input the stock price of apple:'))
# price = eval(input('input the stock price of apple:'))
# # eval 用于实现字符串的功能，比如字符串"3*7"，通过eval("3*7")可以得出21
#
# # 3 换行
# if signal == 'red' and car == 'moving':
#     car = 'stop'
# elif signal == 'green' and car == 'stop':
#     car = 'moving'
#
# if signal == 'red' and \
#         car == 'moving':
#     car = 'stop'
# elif signal == 'green' and \
#         car == 'stop':
#     car = "moving"

# # 4 变量
# pi=3.14
# PI=3.222222
# print(id(pi)) #1525 4572 21968
# print(id(PI)) #1525 1572 21776
# # 每个对象在内存中申请开辟一块空间保存，该对象在内存中的地址称为”引用“
#
# a=5.8
# print(f"a_id:{id(a)}")
# b=5.8
# print(id(b))
# print(id(5.8))
# c=a
# print(f"c_id:{id(c)}")
# # 上面四次id输出都相同，因为在小整数范围内[-5,256]：编译器自动复用同一块内存，提高空间效率

# # 5 赋值
# x, y = 3.14, 3  # 相当于(x,y)=(3.14,3) 等号左右两边都以元组的方式出现
# print("x=", x)
# print("y=", y)


# # 6 基本类型
# complex_1 = 2.4 + 555j
# print(type(complex_1))  # complex
# print(complex_1.real)  # 2.4 实部
# print(complex_1.imag)  # 555.0 虚部
# print(complex_1.conjugate())  # (2.4-555j) 共轭
# print("\n")


# 7 序列类型
# 字符串：单引号，双引号，三引号内的都是字符串 为不可变类型
# 列表：用[]界别,可以存储不同类型的数据对象 为可变类型
# 元组：用()界别,可以存储不同类型的数据对象 为不可变类型
# range对象：用range()函数生成一个不可变的数字序列 为不可变类型
# mystring = 'mystring'
# print("mystring[0]", mystring[0])  # 通过索引值访问单个字符 m
# print("mystring[1:4]", mystring[1:4])  # 通过切片操作访问多个字符 yst
# print("\n")
#
# aList = [1, 'math', 88]
# print("aList:", aList)
# print("aList[2]:", aList[2])
# aList[2] = 5
# print("aLiat:", aList)
# print("aList[2]:", aList[2])
#
# pList = [('AXP', 'American Express Company', '78.51'),
#          ('Ba', 'The Boeing Company', '184.76'),
#          ('CAT', 'Caterpillar Inc.', '96.39'),
#          ('CSCO', 'Cisco Systems, Inc.', '33.71'),
#          ('CVX', 'Chevron Corporation', '106.09')]  # 这是一个列表，列表内部保存的是元组，元组内部保存的元素是字符串
# print(pList)
# print("pList[0]=", pList[0])
# print("pList[-1]=", pList[-1])
# print("pList[1:2:2]", pList[1:2:2])
# print("pList[4:0:-1]", pList[4:0:-1])
#
# for item in zip([1, 2, 3], ['sugar', 'spice', 'everything nice']):
#     print(item)
#
# num = [1, 2, 3, 4, 5, 6, 78, 78, 99, 66, 3, 3, 4, 8]
# print("reversed(num):", list(reversed(num)))  # revrsed()
# print("enumerate(num):", tuple(enumerate(num)))  # enumerate()枚举遍历
# print("min(num):", min(num))  # min()
# print("max(num):", max(num))  # max()
# print("sorted(num):", sorted(num))  # sorted()
# print("sum(num):", sum(num))  # sum()
# print("zip(num):", list(zip(num,('a', 'b', 'c'))))  # zip()
#
#
# def points(list):
#     list.sort()
#     list.pop()
#     list.pop(0)
#     list.append(9)
#     return sum(list)/len(list)
#
# list_1=[9,9,8.5,10,7,8,8,9,8,10]
# print(list_1)
# print(points(list_1))
# print(list_1)
#
# def many(string):
#     string.split(",")
#     print(string)
#     return print(len(string))
#
# lst="B01,B02,B03,B05,B08,B10"
# many(lst)


# # 8 字典与集合
# # 用{}界别 字典的每一个元素键值对：键为不可变对象 值可以是任意类型
# # 字典通过键值进行访问
# dict_1 = {("sin"): 1, 'cos': "2", "tan": [3], "cot": ("tur")}
# print("dict[cot]:", dict_1["cot"])
# print("dict[sin]:", dict_1["sin"], "\t type(dict[sin])", type(dict_1["sin"]))
#
# info=[('Mayue',3000),('Lilin',4500),('Wuyun',8000)]
# binfo=dict(info)
# print("binfo:",binfo)
#
# cinfo=dict([['x',3],['y',45],['z',80]])#传入迭代对象列表创建
# dinfo=dict(Mayue=3000,Lilin=4500,Wuyun=8000)#传入关键字构建
# einfo=dict((('Mayue',3000),('Lilin',4500),('Wuyun',8000)))#传入迭代对象元组创建
# # finfo=dict(('Mayue',3000),('Lilin',4500),('Wuyun',8000))# 报错
# print(cinfo)
# print(dinfo)
# print(einfo)
# # print(finfo)
#
# print("hash('x'):",hash('x'))
# print('dinfo.items():',dinfo.items())


# # 集合
# # 集合内部元素不重复，是一个无序不重复的元素组合
# # 通过set()函数转换成可变集合，frozenset()函数转换成不可变集合
# names = ['Wangdachui', 'Niuyun', 'Wangzi', 'Wangdachui', 'Linling', 'Niuyun']
# print("names:", names)
# print("type(name):", type(names))
# names_set = set(names)#将列表转换成可变集合
# print("names_set:", names_set)
# print("type(name_set):", type(names_set))
# names_frozenset=frozenset(names)
# print("names_frozenset:",names_frozenset)
# print("type(name_frozenset):",type(names_frozenset))


# 程序控制结构
# from random import randint
# x=randint(0,300)
# num=int(input("输入一个猜测值："))
# if num==x:
#     print("yes")
# elif num<x:
#     print("guess low")
# elif num>x:
#     print("guess high")
# else:
#     print("nop")

# from random import randint
# x=randint(0,400)
# for time in range(1,10):# 猜数字游戏
#     print(f"第{time}次输入",end=":")
#     guess=int(input())
#     if guess==x:
#         print("right")
#         break
#     elif guess<x:
#         print("guess low")
#     else:
#         print("guess high")


# x=[x**2 for x in range(10)]# 创建x^2 x从0-9
# print(x)
#
# y=[x for x in range(50)]# 创建从0-49的列表
# print(y)
#
# z=[(x,y) for x in range(5) for y in range(5)]
# print(z)
#
# get_first=[line[0] for line in z]#对列表中的每一个元素line 取第0个元素
# print(get_first)
#
# data=[int(x) for x in input("enter the nums: ").split(',')]
# print(data)
# for x in data:
#     print(x,end="\t")

# data_1=(x for x in range(10))# 生成器 与列表解析生成器类似
# # 生成器是一个返回迭代器的函数，是一种特殊的迭代器，在内部实现迭代器协议
# # 每次计算出一个条目后，把这个条目产生出来，使用惰性计算机制，检索时才赋值，利于大数据处理
# print(data_1)
# sum=sum(x for x in range(10))
# print(sum)
# for i in data_1:
#     print(i,end=" ")

# sum=0
# i=0
# while i<=100:
#     sum+=i
#     i+=1
# print(sum)


# # 9 位运算
# # 只适用于整数，位运算就是按整数的二进制位进行的计算
# # 取反(~) 与(&) 或(|) 异或(^) 左移(<<) 右移(>>)
# print("~1=", ~1)
# print("16<<2=", 16 << 2)
# print("16>>2=", 16 >> 2)
# print("64&15=", 64 & 15)
# print("64|15=", 64 | 15)
# print("64^15=", 64 ^ 15)
#
# # 10 逻辑运算
# # not>and>or
# x, y = 3.1415962535, -1024
# print("not x is y = ", not x is y)  # 同一性运算符 “is” 主要用来判断两个对象的身份标识，即两者的基本要素 “id”，也叫做同一性运算符。
#
# # 11 函数
# import struct
# class Shape:
#     def _dir_(self):
#         return ['area','perimeter','location']
# s=Shape()
# print(dir())

# from datetime import  datetime
# dt=datetime.now()
# print(dt)
#
# def printStr(x):
#     """ print the string"""
#     print(x)
#
# printStr("666")
#
# def sum(x,y):
#     return x+y


# #x,y最大公约数
# def gcd(x,y):
#     if x<y:
#         x,y=y,x
#     while x%y!=0:
#         r=x%y
#         x=y
#         y=r
#     return y
#
# x=eval(input("the first number:"))
# y=eval(input("the seconde number:"))
# gcdxy=gcd(x,y)
# print(f"gcd(x,y)={gcdxy}")

# #求1-100之间的所有素数
# from math import sqrt
# def isprime(x):
#     if x==1:
#         return False
#     k=int(sqrt(x))
#     for j in range(2,k+1):
#         if x%j==0:
#             return False
#     return True
#
# for i in range(1,100):
#     if isprime(i):
#         print(i,end=" ")


# #编写函数计算平均成绩
# #根据给出的一组学生的3门课成绩信息，编写函数计算每个学生的平均成绩，返回平均成绩最高和最低两位学生的姓名
# def search(scores):
#     maxScore=0
#     minScore=100
#     for k,v in scores.items():
#         aveg = (scores[k][0] + scores[k][1] + scores[k][2]) // 3
#         if aveg >= maxScore:
#             maxScore = aveg
#             maxName = k
#         if aveg <= minScore:
#             minScore = aveg
#             minName = k
#     return maxName, minName
#
# if __name__ == "__main__":
#     dictScores = {'Jerry': [87, 85, 91], 'Mary': [76, 83, 88], 'Tim': [97, 95, 89], 'John': [77, 83, 81]}
#     maxName, minName = search(dictScores)
#     print('{0} got the first place, {1} got the last.'.format(maxName, minName))
#
# #可变长参数-可变长位置参数/可变长关键字参数
# def greeting(args1, *tupleArgs, **dictArgs):
#                 print(args1)
#                 print(tupleArgs)
#                 print(dictArgs)
# names = ['Wangdachuan', 'Liuyun', 'Linling']
# info = {'schoolName' : 'NJU', 'City' : 'Nanjing'}
# greeting('Hello,', *names, **info)

# 12 面向对象程序设计
# 包括：抽象，继承，多态
# class Test:
#     def __init__(self):
#         print("__init__")
#
#     def __del__(self):
#         print("__del__")
#
#
# if __name__ == '__main__':
#     x = Test()
#     y = x
#     z = y
#     print(f"x_id:{id(x)}\ty_id:{id(y)}\tz_id:{id(z)}")

# 13 异常
# print(dir(__builtins__))#查看异常类
# # #采用 try:  except 语句
# try:
#     num1=int(input("number1:"))
#     num2=int(input("number2:"))
#     print(num1/num2)
# except ValueError:
#     print("输入无效参数")
# except ZeroDivisionError as error_1:
#     print("分母不能为0")
#     print(error_1)
# # 相当于 except (ValueError,ZeroDivisionError):
#
# try:
#     x=6
#     y=z
#     nums2=0
#     print(nums1/nums2)
# except:#如果没有参数则默认捕捉所有异常
#     print("出现错误")

# 14 包
# 一个有层次的文件目录结构 定义了一个由模块和子包组成的python应用程序执行环境
